from time import sleep
import socket
import time

def main():
    # udp 通信地址，IP+端口号
    udp_addr = ('127.0.0.1', 9999)
    udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    # 发送数据到指定的ip和端口,每隔1s发送一次，发送10次
    for i in range(10):
        milliseconds = int(time.time()*1000)
        # udp_socket.sendto(("Hello,I am a UDP socket for: " + str(i)) .encode('utf-8'), udp_addr)
        # print("send %d message" % i)
        udp_socket.sendto("a".encode('utf-8'),udp_addr)
        sleep(1)
        print("%d"%milliseconds)

    # 5. 关闭套接字
    udp_socket.close()


if __name__ == '__main__':
    print("udp client ")
    main()
